const Koa = require('koa');
const Router = require('@koa/router');
const app = new Koa();
const router = new Router();
const ResponseTime = require('./middleware/responseTime.js')
const Upload = require('./middleware/upload')
const GetFile = require('./middleware/getFile.js')
const GetFileInfo = require('./middleware/getFileInfo.js')

// upload
router.post('/upload', Upload)
// 获取图片信息参数
router.get('/info/:date/:file', GetFileInfo)
// 获取图片，resize图片
router.get('/:date/:file', GetFile)

// 响应时间
app.use(ResponseTime);
app.use(router.routes()).use(router.allowedMethods());
app.use(async ctx => {
  ctx.body = ctx.method + ' ' + ctx.url
});
app.on('error', (err, ctx) => {
  // nothing to do!
});
app.listen(3001);
